package com.tutorial.transactional.service.impl;

import com.tutorial.transactional.mapper.AccountMapper;
import com.tutorial.transactional.service.IAccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;

@Service("accountService")
public class AccountServiceImpl implements IAccountService {
    @Autowired
    private AccountMapper accountMapper;



    @Override
    @Transactional(isolation = Isolation.READ_COMMITTED,propagation = Propagation.REQUIRED)
    public void transferMoney(String outAccount, String inAccount, BigDecimal money) {
        accountMapper.decrMoney(outAccount, money);
        // int i = 1 / 0;
        accountMapper.incrMoney(inAccount, money);
    }
}
